﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using System.Data.SqlClient;
using System.Data;

namespace DAL
{
    public class ETLSYSJobConfigStepDAL: DB
    {
        public ETLSYSJobConfigStepDAL(LoginInfo info)
        {
            base.loginInfo = info;
        }
        public bool Add(ETLSYSJobConfigStep data)
        {
            bool result = true;
            try
            {
                HIDB.dbo con = base.conn();
                SqlParameter[] sqlparams = new SqlParameter[]
                { 
                     new  SqlParameter("@GUID",data.GUID)
                    ,new  SqlParameter("@JobID",data.JobID)
                    ,new  SqlParameter("@StepID",data.StepID)
                    ,new  SqlParameter("@StepOrderID",data.StepOrderID)
                    ,new  SqlParameter("@StepName",data.StepName)
                    ,new  SqlParameter("@StepDescription",data.StepDescription)
                    ,new  SqlParameter("@StepStatus",data.StepStatus)
                    ,new  SqlParameter("@StepType",data.StepType)  
                };
                con.StoredUpdate("[Working_db].[UP_ETL_SYS_JobConfig_Step_Insert]", sqlparams);
            }
            catch (Exception)
            {
                result = false;
                throw;
            }
            return result;
        }

        public ETLSYSJobConfigStep GetItemByStepID(string stepID)
        {
            ETLSYSJobConfigStep result = null;
            try
            {
                HIDB.dbo con = base.conn();
                SqlParameter[] sqlparams = new SqlParameter[] { new SqlParameter("@StepID", stepID) };
                DataTable dt = con.StoredDataTable("[Working_db].[UP_ETL_SYS_JobConfig_Step_GetItemByStepID]", sqlparams);
                if (dt != null && dt.Rows.Count > 0)
                {
                    result = new ETLSYSJobConfigStep();
                    result.GUID = dt.Rows[0]["GUID"].ToString();
                    result.JobID = dt.Rows[0]["JobID"].ToString();
                    result.StepID = dt.Rows[0]["StepID"].ToString();
                    result.StepOrderID = int.Parse(dt.Rows[0]["StepOrderID"].ToString());
                    result.StepName = dt.Rows[0]["StepName"].ToString();
                    result.StepDescription = dt.Rows[0]["StepDescription"].ToString();
                    result.StepStatus = int.Parse(dt.Rows[0]["StepStatus"].ToString());
                }
            }
            catch (Exception)
            {
                result = null;
                throw;
            }
            return result;
        }
    }
}
